/*
 * Copyright 2025 The Android BYOD Project
 */

package com.example.testble;

import android.content.Context;
import android.content.SharedPreferences;
import java.util.Map;

/**
 * SharedPrefsUtils is a utility class for accessing and modifying SharedPreferences data in
 * Android. It provides convenient static methods for saving and retrieving common data types such
 * as int, long, boolean, and String from a single SharedPreferences file named "shared_refs".
 *
 * <p>Features: - Save and retrieve values with type safety. - Automatically applies changes
 * asynchronously using SharedPreferences.Editor.apply(). - Centralized management of default values
 * for each type.
 *
 * <p>Note: - All methods require a non-null Context, and will throw IllegalArgumentException if
 * context is null. - Default return values are used when no value is found: INT_DEFAULT = -1
 * LONG_DEFAULT = -1L BOOLEAN_DEFAULT = false STRING_DEFAULT = null
 *
 * <p>Example usage: SharedPrefsUtils.saveString(context, "key", "value"); String value =
 * SharedPrefsUtils.getString(context, "key");
 */
public class SharedPrefsUtils {
    public static final String NAME = "shared_refs";
    public static final int INT_DEFAULT = -1;
    public static final long LONG_DEFAULT = -1L;
    public static final boolean BOOLEAN_DEFAULT = false;
    public static final String STRING_DEFAULT = null;

    public SharedPrefsUtils() {}

    public static void saveInt(Context var0, String var1, int var2) {
        if (var0 == null) {
            throw new IllegalArgumentException(
                    "SharedPrefsUtils:saveInt error, context must not be null.");
        } else {
            SharedPreferences.Editor var3;
            (var3 = var0.getSharedPreferences("shared_refs", 0).edit()).putInt(var1, var2);
            var3.apply();
        }
    }

    public static int getInt(Context var0, String var1) {
        if (var0 == null) {
            throw new IllegalArgumentException(
                    "SharedPrefsUtils:getInt error, context must not be null.");
        } else {
            return var0.getSharedPreferences("shared_refs", 0).getInt(var1, -1);
        }
    }

    public static void saveLong(Context var0, String var1, long var2) {
        if (var0 == null) {
            throw new IllegalArgumentException(
                    "SharedPrefsUtils:saveLong error, context must not be null.");
        } else {
            SharedPreferences.Editor var4;
            (var4 = var0.getSharedPreferences("shared_refs", 0).edit()).putLong(var1, var2);
            var4.apply();
        }
    }

    public static long getLong(Context var0, String var1) {
        if (var0 == null) {
            throw new IllegalArgumentException(
                    "SharedPrefsUtils:getLong error, context must not be null.");
        } else {
            return var0.getSharedPreferences("shared_refs", 0).getLong(var1, -1L);
        }
    }

    public static void saveBoolean(Context var0, String var1, boolean var2) {
        if (var0 == null) {
            throw new IllegalArgumentException(
                    "SharedPrefsUtils:saveBoolean error, context must not be null.");
        } else {
            SharedPreferences.Editor var3;
            (var3 = var0.getSharedPreferences("shared_refs", 0).edit()).putBoolean(var1, var2);
            var3.apply();
        }
    }

    public static boolean getBoolean(Context var0, String var1) {
        if (var0 == null) {
            throw new IllegalArgumentException(
                    "SharedPrefsUtils:getBoolean error, context must not be null.");
        } else {
            return var0.getSharedPreferences("shared_refs", 0).getBoolean(var1, false);
        }
    }

    public static boolean getBoolean(Context var0, String var1, boolean var2) {
        if (var0 == null) {
            throw new IllegalArgumentException(
                    "SharedPrefsUtils:getBoolean error, context must not be null.");
        } else {
            return var0.getSharedPreferences("shared_refs", 0).getBoolean(var1, var2);
        }
    }

    public static void saveString(Context var0, String var1, String var2) {
        if (var0 == null) {
            throw new IllegalArgumentException(
                    "SharedPrefsUtils:saveString error, context must not be null.");
        } else {
            SharedPreferences.Editor var3;
            (var3 = var0.getSharedPreferences("shared_refs", 0).edit()).putString(var1, var2);
            var3.apply();
        }
    }

    public static String getString(Context var0, String var1) {
        if (var0 == null) {
            throw new IllegalArgumentException(
                    "SharedPrefsUtils:getString error, context must not be null.");
        } else {
            return var0.getSharedPreferences("shared_refs", 0).getString(var1, STRING_DEFAULT);
        }
    }

    public static String getString(Context var0, String var1, String var2) {
        if (var0 == null) {
            throw new IllegalArgumentException(
                    "SharedPrefsUtils:getString error, context must not be null.");
        } else {
            return var0.getSharedPreferences("shared_refs", 0).getString(var1, var2);
        }
    }

    public static Map<String, String> getAll(Context var0) {
        if (var0 == null) {
            throw new IllegalArgumentException(
                    "SharedPrefsUtils:getAll error, context must not be null.");
        } else {
            return (Map<String, String>) var0.getSharedPreferences("shared_refs", 0).getAll();
        }
    }
}
